package com.csg.ses.feign;

import cn.csg.soa.mk.FscfdhjgtzIN;
import cn.csg.soa.mk.FscfdhjgtzOUT;
import com.alibaba.fastjson.JSON;
import com.csg.ses.service.ses.SysInterfaceLogService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @auther wangjun
 * @time 2020/11/18 14:56
 * 营销系统webservice接口调用
 */
@Service
public class YxxtService {

    @Autowired
    private SysInterfaceLogService logService;

    /**
     * 调用营销系统webservice接口，发送催费电话结果通知
     * @param dqbm
     * @param znxtpch
     * @param pcjls
     * @param wsUrl
     * @return
     */
    public Boolean fscfdhjgtz(String dqbm, String znxtpch, String pcjls, String wsUrl) {
        FscfdhjgtzIN fscfdhjgtzIN = new FscfdhjgtzIN();
        fscfdhjgtzIN.setDQBM(dqbm);
        fscfdhjgtzIN.setZNXTPCH(znxtpch);
        fscfdhjgtzIN.setPCJLS(pcjls);

        FscfdhjgtzOUT result = null;
        String[] inParams = fscfdhjgtzIN != null ? new String[] {JSON.toJSONString(fscfdhjgtzIN)} : null;
        Long logId = logService.insertLog("发送催费电话结果通知", wsUrl, "yxxt", inParams); //插入日志记录
        Boolean isSuccess = false;
        String[] outParams = null;
        try {
            JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
            Client client = dcf.createClient(wsUrl);
            Object[] objects = client.invoke("fscfdhjgtz", fscfdhjgtzIN);
            result = (FscfdhjgtzOUT) objects[0];
            isSuccess = true;
            outParams = new String[] {JSON.toJSONString(result)};
        } catch (Exception e) {
            outParams = new String[] {"调用" + wsUrl + "失败！", e.getCause().getMessage()};
            e.printStackTrace();
        } finally {
            logService.updateLog(logId, isSuccess, outParams);  //更新日志记录
            return isSuccess;
        }
    }
}